package cn.com.xyzq.reks.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.appfuse.model.BaseObject;

@Entity
@Table(name = "staff_result")
@XmlRootElement
public class StaffResult extends BaseObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7012083260699440866L;
	private Long id;
	private Staff staff;
	private Double deal;
	private Double worth;
	private Double netCommission;
	private Double grade;
	private Date month;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST,
			CascadeType.MERGE })
	@JoinColumn(name = "staff_id")
	public Staff getStaff() {
		return staff;
	}

	@Column(name = "deal", precision = 20, scale = 2)
	public Double getDeal() {
		return deal;
	}

	@Column(name = "worth", precision = 20, scale = 2)
	public Double getWorth() {
		return worth;
	}

	@Column(name = "net_commission", precision = 20, scale = 2)
	public Double getNetCommission() {
		return netCommission;
	}

	@Column(name = "grade", precision = 3, scale = 2)
	public Double getGrade() {
		return grade;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "month", length = 10)
	public Date getMonth() {
		return month;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setStaff(Staff staff) {
		this.staff = staff;
	}

	public void setDeal(Double deal) {
		this.deal = deal;
	}

	public void setWorth(Double worth) {
		this.worth = worth;
	}

	public void setNetCommission(Double netCommission) {
		this.netCommission = netCommission;
	}

	public void setGrade(Double grade) {
		this.grade = grade;
	}

	public void setMonth(Date month) {
		this.month = month;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
				.append("staff ID", staff.getStaffId())
				.append("name", staff.getName()).append("deal", deal)
				.append("worth", worth).append("net Commission", netCommission)
				.append("grade", grade).append("month", month).toString();
	}

	@Override
	public boolean equals(Object o) {
		// TODO Auto-generated method stub
		if (this == o) {
			return true;
		}
		if (!(o instanceof StaffResult)) {
			return false;
		}
		final StaffResult sr1 = (StaffResult) o;
		return this.hashCode() == sr1.hashCode();
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		int result;
		result = (id != null ? id.hashCode() : 0);
		result = 29 * result + (staff != null ? staff.hashCode() : 0);
		result = 29 * result + (deal != null ? deal.hashCode() : 0);
		result = 29 * result + (worth != null ? worth.hashCode() : 0);
		result = 29 * result
				+ (netCommission != null ? netCommission.hashCode() : 0);
		result = 29 * result + (grade != null ? grade.hashCode() : 0);
		result = 29 * result + (month != null ? month.hashCode() : 0);
		return result;
	}

}
